<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<h2>图书信息修改</h2>
<?php
include_once("database.php");
//先判断是否修改动作
if(isset($_POST["submit"])&&$_POST["submit"]=="修改"){
	//点击了修改按钮后开始操作数据库
	$isbn=$_POST["ISBN"];
	$name=$_POST["name"];
	$price=$_POST["price"];
	$print=$_POST["print"];
	$editor=$_POST["editor"];
	$wordnum=$_POST["wordnum"];
	$press=$_POST["press"];
	$pressdate=$_POST["pressdate"];
	$contentsinfo=$_POST["contentsinfo"];
	$othersinfos=$_POST["othersinfos"];
	//构建修改语句
	$updatebookssql="update books set name='$name',price={$price},print='$print',editor='$editor',wordnum='$wordnum',press='$press',pressdate='$pressdate',contentsinfo='$contentsinfo',othersinfos='$othersinfos' where ISBN='$isbn'";
	@mysql_query($updatebookssql) or die("修改书籍信息失败:".mysql_error()."<br/>");
	//然后跳转到查询界面
	echo "修改ISBN号为:$isbn 书籍数据成功!<br/><br/>跳转到查询图书页面......<br/>";
	header("Refresh:3;url=selectbook.php");
	exit;
}
//在判断是否获取ISBN号
if(isset($_GET["ISBN"])){
	$isbn=$_GET["ISBN"];
	echo "当前需要修改的图书号为:{$isbn}<br/>";
}else{
	echo '<p>请先往"查询图书"界面查询到指定的图书然后再进行更新动作!</p>';
	exit;
}
//获取指定isbn号的书籍信息

$isbn=$_GET["ISBN"];
$selectsql="select * from books where ISBN='$isbn'";
$result=mysql_query($selectsql);//查询数据库
$row=mysql_fetch_array($result,MYSQL_ASSOC);
$isbn=$row["ISBN"];
$name=$row["name"];
$price=$row["price"];
$print=$row["print"];
$editor=$row["editor"];
$wordnum=$row["wordnum"];
$press=$row["press"];
$pressdate=$row["pressdate"];
$contentsinfo=$row["contentsinfo"];
$othersinfos=$row["othersinfos"];
$updatetable=<<<form
<form action="" method="post">
<h2>添加图书</h2>
&nbsp;&nbsp;ISBN:<input type="text" name="ISBN" value="$isbn" readonly="readonly">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;书名:<input type="text" name="name" value="$name"><br/><br/>
&nbsp;&nbsp;定价:<input type="text" name="price" value="$price">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;印刷:<input type="text" name="print" value="$print"><br/><br/>
&nbsp;&nbsp;主编:<input type="text" name="editor" value="$editor">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;字数:<input type="text" name="wordnum" value="$wordnum"><br/><br/>
出版社:<input type="text" name="press" value="$press">&nbsp;&nbsp;&nbsp;
出版日期:<input type="text" name="pressdate" value="$pressdate"><br/><br/>
内容摘要:<br/><textarea name="contentsinfo" rows="10" cols="140">{$contentsinfo}</textarea><br/><br/>
备注信息:<br/><textarea name="othersinfos" rows="10" cols="140">{$othersinfos}</textarea><br/><br/>
&nbsp;&nbsp;&nbsp;
<input type="submit" name="submit" value="修改">
</form>
form;
echo $updatetable;
?>

</body>
</html>